/* GUI CONVERTED from sqqomtlb.p (converter v1.76) Wed May 22 00:58:54 2002 */
/* sqqomtlb.p - QUOTE MAINTENANCE LINE SUBROUTINE                             */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.13.2.11 $                                                     */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.4      LAST MODIFIED: 07/06/93   BY: dpm           *H023**/
/* REVISION: 7.4      LAST MODIFIED: 11/19/93   BY: cdt           *H086**/
/* REVISION: 7.4      LAST MODIFIED: 12/13/93   BY: bcm           *GH94**/
/* REVISION: 7.4      LAST MODIFIED: 02/16/94   BY: dpm           *FM10**/
/* REVISION: 7.4      LAST MODIFIED: 08/29/94   BY: bcm           *H494**/
/* REVISION: 7.4      LAST MODIFIED: 09/25/94   BY: dpm           *FR50**/
/* REVISION: 7.4      LAST MODIFIED: 10/28/94   BY: dpm           *FR95**/
/* REVISION: 7.4      LAST MODIFIED: 11/11/94   BY: dpm           *FT57**/
/* REVISION: 7.4      LAST MODIFIED: 11/22/94   BY: afs           *H605**/
/* REVISION: 7.4      LAST MODIFIED: 02/23/95   BY: jzw           *H0BM**/
/* REVISION: 8.5      LAST MODIFIED: 03/22/95   BY: jlf           *J042**/
/* REVISION: 7.4      LAST MODIFIED: 06/13/95   BY: bcm           *H0DW**/
/* REVISION: 7.4      LAST MODIFIED: 11/16/95   BY: ais           *H0H2**/
/* REVISION: 8.5      LAST MODIFIED: 11/07/95   BY: taf           *J053**/
/* REVISION: 8.5      LAST MODIFIED: 05/13/96   BY: tzp           *G1V8**/
/* REVISION: 8.5      LAST MODIFIED: 06/21/96   BY: tzp           *G1XB**/
/* REVISION: 8.6      LAST MODIFIED: 09/26/96   BY: svs           *K007**/
/* REVISION: 8.6      LAST MODIFIED: 11/05/96   BY: *H0NR* Suresh Nayak       */
/* REVISION: 8.6      LAST MODIFIED: 12/31/96   BY: *K03Y* Jean Miller        */
/* REVISION: 8.6      LAST MODIFIED: 02/20/97   BY: *H0SJ* Suresh Nayak       */
/* REVISION: 8.6      LAST MODIFIED: 08/06/97   BY: *J1YG* Seema Varma        */
/* REVISION: 8.6      LAST MODIFIED: 11/18/97   BY: *J25B* Aruna Patil        */
/* REVISION: 8.6      LAST MODIFIED: 01/23/98   BY: *J2BW* Nirav Parikh       */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/09/98   BY: *L00Y* Jeff Wootton       */
/* REVISION: 9.1      LAST MODIFIED: 07/05/99   BY: *N00V* Jyoti Thatte       */
/* Old ECO marker removed, but no ECO header exists *F042*                    */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Patti Gaultney     */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KN* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 12/18/00   BY: *M0TZ* Veena Lad          */
/* REVISION: 9.1      LAST MODIFIED: 09/23/00   BY: *N0WC* BalbeerS Rajput    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.13.2.7       BY: Katie Hilbert      DATE: 04/01/01 ECO: *P002* */
/* Revision: 1.13.2.9       BY: Santhosh Nair      DATE: 03/06/02 ECO: *M1H1* */
/* $Revision: 1.13.2.11 $   BY: Jean Miller        DATE: 05/07/02 ECO: *P05M* */
/* $Revision: 1.13.2.11 $   BY: Ashish M.          DATE: 05/20/02 ECO: *P04J* */
/* REVISION: EB2 SP3 GUI  LAST MODIFIED: 11/03/03   BY: Joy Huang  *hk-s-015* */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}
{cxcustom.i "SQQOMTLB.P"}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */


/* DEFINE RNDMTHD FOR CALL TO GPFRLWT.P */
define shared variable rndmthd like rnd_rnd_mthd.
define shared variable del-yn like mfc_logical.
define shared variable prev_due like qod_due_date.
define shared variable prev_qty_ord like qod_qty_quot.
define shared variable part as character format "x(18)".
define shared variable qo_recno as recid.
define shared variable pt_reco as recid.
define shared variable promise_date as date label "Promise Date".
define shared variable rsn_lost like qod_rsn_lost.
define shared variable qoclcmmts like mfc_logical.
define shared variable qod_recno as recid.
define shared variable pcqty like qod_qty_quot.
define shared variable cmtindx like cmt_indx.
define shared variable desc1 like pt_desc1.
define shared variable qodcmmts like soc_lcmmts label "Comments".
define shared variable sngl_ln like soc_ln_fmt.
define shared variable clines as integer.
define shared variable line like qod_line.
define shared variable newline like mfc_logical.
define shared variable sqqomtla_error like mfc_logical.
define shared variable err_stat as integer.
define shared variable new_site like sod_site.
define shared variable old_site like sod_site.
define shared variable match_pt_um like mfc_logical.
define shared variable old_qod_site like qod_site.
define shared variable zone_to like txz_tax_zone.
define shared variable zone_from like txz_tax_zone.
define shared variable tax_usage like qo_tax_usage no-undo.
define shared variable tax_env like qo_tax_env no-undo.
define shared variable freight_ok like mfc_logical.
define shared variable old_ft_type like ft_type.
define shared variable calc_fr like mfc_logical.
define shared variable disp_fr like mfc_logical.
define shared variable qoc_pc_line  like mfc_logical.
define shared variable undo_all2    like mfc_logical.
define shared variable discount     as decimal.
define shared variable reprice_dtl  like mfc_logical.
define shared variable new_order    like mfc_logical.

/* THE SHARED VARIABLE current_fr_terms IS DEFINED IN pppivar.i, BUT */
/* SINCE ONLY THIS VARIABLE IS REQUIRED, TO AVOID OVERHEADS IT HAS   */
/* BEEN EXPLICITLY DEFINED HERE, INSTEAD OF CALLING PPPIVAR.I        */
define shared variable current_fr_terms   like so_fr_terms.

define variable yn            like mfc_logical.
define variable valid_acct    like mfc_logical.
define variable detqty        like qod_qty_quot.
define variable glvalid       like mfc_logical.
define variable ptstatus      like pt_status   no-undo.
define variable l_old_fr_list like qod_fr_list no-undo.

define shared frame c.
define shared frame d.

/*THIS TEMP TABLE IS CREATED TO CALCULATE FREIGHT CHARGES  */
/*WHEN A NEW SALES QUOTE LINE IS ADDED TO AN EXISTING QUOTE*/
/*WHEN THE FREIGHT TYPE IS "INCLUDE".                      */
define shared temp-table l_fr_table
   field l_fr_qodnbr  like qod_nbr
   field l_fr_qodline like qod_line
   field l_fr_chrg    like qod_fr_chg
   field l_qodlist_pr like qod_list_pr
   index nbrline is primary l_fr_qodnbr l_fr_qodline.

/* DECLARATIONS FOR gptxcval.i */
{gptxcdec.i}

/*DEFINE SHARED FORMS*/
/*HK-S-015          {sqlinfrm.i}*/
/*HK-S-015*/        {xxsqlinfrm.i}

undo_all2 = yes.

find qo_mstr where recid(qo_mstr) = qo_recno.
find qod_det where recid(qod_det) = qod_recno.

find first soc_ctrl no-lock.
find first gl_ctrl no-lock.

/* SET SALES, DISCOUNT ACCOUNTS BASED ON  */
/* PRODUCT LINE, SITE, CUST TYPE, CHANNEL */
find pt_mstr where pt_part = qod_part no-lock no-error.
if available pt_mstr then
   pt_recno = recid(pt_mstr).
else
   pt_recno = ?.

if newline then do:
   /* Set Sales and Cost of Goods Accounts */
   {gprun.i ""sqplsd.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

end.

{&SQQOMTLB-P-TAG1}
if newline then
   qod_rel_chg = qod_qty_quot.

if sngl_ln then
   display
      desc1
      qod_fr_list
      qod_loc
      qod_site
      qod_acct
      qod_sub
      qod_cc
      qod_project
      qod_serial
      qod_dsc_acct
      qod_dsc_sub
      qod_dsc_cc
      qod_dsc_project
      qod_rel_chg
      qod_type
      qod_qty_rel
      qod_um_conv
/*HK-S-015      qod_std_cost when (not available pt_mstr)*/
      qod_rsn_lost
      qod_fix_pr
      qod_taxable
      qod_taxc
      qod_req_date
      qodcmmts
      qod_per_date
      qod_crt_int
      qod_due_date
      qod_pricing_dt
   with frame d.

l_old_fr_list = qod_fr_list.

if sngl_ln then
seta:
do with frame d on error undo, retry on endkey undo, leave seta:
/*GUI*/ if global-beam-me-up then undo, leave.


   set
      /* Column 1 */
      desc1                   when (not available pt_mstr)
      qod_loc
      qod_serial
      qod_rel_chg
/*HK-S-015      qod_std_cost*/
      qod_fix_pr
      qod_req_date
      qod_per_date
      qod_due_date

      /* Column 2 */
      qod_fr_list
      qod_acct
      qod_sub
      qod_cc
      qod_project
      qod_dsc_acct            when (newline or reprice_dtl)
      qod_dsc_sub             when (newline or reprice_dtl)
      qod_dsc_cc              when (newline or reprice_dtl)
      qod_dsc_project         when (newline or reprice_dtl)
      qod_type                when (available pt_mstr)
      qod_um_conv
      qod_rsn_lost
      qod_taxable
      qod_taxc
      qodcmmts.

   if not available pt_mstr then qod_desc = desc1.

   /* INITIALIZE SETTINGS */
   {gprunp.i "gpglvpl" "p" "initialize"}

   /* ACCT/SUB/CC/PROJ VALIDATION */
   {gprunp.i "gpglvpl" "p" "validate_fullcode"
      "(input  qod_acct,
        input  qod_sub,
        input  qod_cc,
        input  qod_project,
        output valid_acct)"}

   if valid_acct = no then do:
      next-prompt qod_acct with frame d.
      undo, retry.
   end.

   /* INITIALIZE SETTINGS */
   {gprunp.i "gpglvpl" "p" "initialize"}

   /* ACCT/SUB/CC/PROJ VALIDATION */
   {gprunp.i "gpglvpl" "p" "validate_fullcode"
      "(input  qod_dsc_acct,
        input  qod_dsc_sub,
        input  qod_dsc_cc,
        input  qod_dsc_project,
        output valid_acct)"}

   if valid_acct = no then do:
      next-prompt qod_dsc_acct with frame d.
      undo seta, retry.
   end.

   if qo_curr <> base_curr then do:

      find ac_mstr where ac_code = qod_acct
      no-lock no-error.
      if available ac_mstr and ac_curr <> qo_curr
         and ac_curr <> base_curr
      then do:
         {pxmsg.i &MSGNUM=134 &ERRORLEVEL=3}
         /*ACCT CURR MUST BE TRANS OR BASE CURR*/
         next-prompt qod_acct with frame d.
         undo, retry.
      end. /* end of if available ac_mstr and ac_curr <> qo_curr */

      find ac_mstr where ac_code = qod_dsc_acct
      no-lock no-error.
      if available ac_mstr and ac_curr <> qo_curr
         and ac_curr <> base_curr then do:
         {pxmsg.i &MSGNUM=134 &ERRORLEVEL=3}
         /*ACCT CURR MUST BE TRANS OR BASE CURR*/
         next-prompt qod_dsc_acct with frame d.
         undo, retry.
      end. /* end of if available ac_mstr and ac_curr <> qo_curr */

   end. /* end of if qo_curr <> base_curr                        */

   /* VALADATE  TAXCODE */
   {gptxcval.i &code=qod_taxc  &frame="d"}

   /* VALIDATE FREIGHT LIST */
   if qod_fr_list <> "" then do:
      find fr_mstr where fr_list = qod_fr_list and
                         fr_site = qod_site and
                         fr_curr = qo_curr
      no-lock no-error.
      if not available fr_mstr then
         find fr_mstr where fr_list = qod_fr_list and
                            fr_site = qod_site and
                            fr_curr = gl_base_curr
         no-lock no-error.
      if not available fr_mstr then do:
         /* FREIGHT LIST # NOT FOUND FOR SITE # CURRENCY */
         {pxmsg.i &MSGNUM=670 &ERRORLEVEL=4
                  &MSGARG1=qod_fr_list
                  &MSGARG2=qod_site
                  &MSGARG3=qo_curr}
         next-prompt qod_fr_list with frame d.
         undo, retry.
      end.
   end.

   if qod_rsn_lost <> "" then do:
      find rsn_ref where rsn_code = qod_rsn_lost
                     and rsn_type = "QUOTE"
      no-lock no-error.
      if not available rsn_ref then do:
         {pxmsg.i &MSGNUM=655 &ERRORLEVEL=3} /* INVALID REASON CODE */
         next-prompt qod_rsn_lost with frame d.
         undo, retry.
      end.
   end.
end.

else do: /* multi line */

   {gptxcval.i &code=qod_taxc &frame="NO-FRAME"}

   /* Validate accounts and cost centers */
   /* As they don't get validated in multi line format */

   /* INITIALIZE SETTINGS */
   {gprunp.i "gpglvpl" "p" "initialize"}

   /* ACCT/SUB/CC/PROJ VALIDATION */
   {gprunp.i "gpglvpl" "p" "validate_fullcode"
      "(input  qod_acct,
        input  qod_sub,
        input  qod_cc,
        input  qod_project,
        output glvalid)"}
   if glvalid = no then do:
      undo_all2 = true.
      leave.
   end.

   /* INITIALIZE SETTINGS */
   {gprunp.i "gpglvpl" "p" "initialize"}

   /* ACCT/SUB/CC/PROJ VALIDATION */
   {gprunp.i "gpglvpl" "p" "validate_fullcode"
      "(input  qod_dsc_acct,
        input  qod_dsc_sub,
        input  qod_dsc_cc,
        input  qod_dsc_project,
        output glvalid)"}
   if glvalid = no then do:
      undo_all2 = true.
      leave.
   end.

   if qo_curr <> base_curr then do:

      find ac_mstr where ac_code = qod_acct
      no-lock no-error.
      if available ac_mstr and ac_curr <> qo_curr
         and ac_curr <> base_curr then do:
         {pxmsg.i &MSGNUM=134 &ERRORLEVEL=3}
         /*ACCT CURR MUST BE TRANS OR BASE CURR*/
         pause.
         undo_all2 = true.
         leave.
      end. /* end of if available ac_mstr and ac_curr <> qo_curr */

      find ac_mstr where ac_code = qod_dsc_acct
      no-lock no-error.
      if available ac_mstr and ac_curr <> qo_curr
         and ac_curr <> base_curr then do:
         {pxmsg.i &MSGNUM=134 &ERRORLEVEL=3}
         /*ACCT CURR MUST BE TRANS OR BASE CURR*/
         pause.
         undo_all2 = true.
         leave.
      end. /* end of if available ac_mstr and ac_curr <> qo_curr */

   end. /* end of if qo_curr <> base_curr                        */

end.

if not can-find(pt_mstr where pt_part = qod_part)
   and qod_type  = ""
then do:
   /* Ship type set to (M)emo */
   {pxmsg.i &MSGNUM=25 &ERRORLEVEL=2}
   qod_type = "M".
end.

if available pt_mstr and qod_rel_chg > 0  then do:

   assign
      ptstatus  = pt_status
      substring(ptstatus,9,1) = "#".

   find first isd_det no-lock
      where (isd_status = ptstatus
         and isd_tr_type = "ADD-SO")
   no-error.
   if available isd_det then do:
      /*Restrictive Transaction */
      {pxmsg.i &MSGNUM=358 &ERRORLEVEL=2 &MSGARG1=pt_status}
      do on endkey undo, leave:
         pause.
      end.
   end.

   find first isd_det no-lock
      where (isd_status = ptstatus
         and isd_tr_type = "ORD-SO")
   no-error.
   if available isd_det then do:
      /*Restrictive Transaction */
      {pxmsg.i &MSGNUM=358 &ERRORLEVEL=2 &MSGARG1=pt_status}
      do on endkey undo, leave:
         pause.
      end.
   end.

end. /* end of available pt_mstr and qod_rel_chg >0 ... */

if qod_fr_list <> l_old_fr_list
then
   qod_manual_fr_list = yes.

/* FREIGHT WEIGHTS */
if qod_fr_list <> "" then do:
set_wt:

   do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


      freight_ok = yes.

      if sngl_ln and (calc_fr or disp_fr) then do:

         /* ASSIGN qo_fr_terms WITH THE FREIGHT TERMS FROM     */
         /* THE BEST PRICING ROUTINE TO PREVENT ANY ERROR OR   */
         /* WARNING MESSAGES FROM BEING DISPLAYED AT THE LINE  */
         /* LEVEL                                              */
         if current_fr_terms <> ""
            and qo_manual_fr_terms  = no

         then
            qo_fr_terms = current_fr_terms.

         detqty = qod_qty_quot - qod_qty_rel.

         if old_ft_type = "5"
         then do:
            for first l_fr_table
                where l_fr_qodnbr  = qod_nbr
                and   l_fr_qodline = qod_line
            no-lock: end.

            if not available l_fr_table
            then do:
               create l_fr_table.
                  assign
                     l_fr_qodnbr   = qod_nbr
                     l_fr_qodline  = qod_line
                     l_fr_chrg    = 0
                     l_qodlist_pr = (if reprice_dtl then qod_list_pr
                                     else 0).
            end. /* IF NOT AVAILABLE l_fr_table */

            l_fr_chrg = (if newline then 0
                         else qod_fr_chg).

         end. /* IF old_ft_type = "5" */

         /* If it is a valid date, use the due date.  Otherwise, */
         /* Use the current date                                 */
         {gprun.i ""gpfrlwt.p""
            "(input qo_curr,
              input qo_ex_rate,
              input qo_ex_rate2,
              input qo_fr_min_wt,
              input qo_fr_terms,
              input qo_ship,
              if qod_due_date <> ? then qod_due_date else today,
              input qod_fr_list,
              input qod_part,
              input detqty,
              input qod_site,
              input qod_type,
              input qod_um,
              input calc_fr,
              input disp_fr,
              input-output qod_fr_wt,
              input-output qod_fr_wt_um,
              input-output qod_fr_class,
              input-output qod_fr_chg,
              input-output freight_ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      if not freight_ok then do:
         /* Freight error detected - charges may be incomplete */
         {pxmsg.i &MSGNUM=669 &ERRORLEVEL=2}
         undo set_wt, leave set_wt.
      end.
   end.
end.

{gprun.i ""sqqomtlc.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


{&SQQOMTLB-P-TAG2}
undo_all2 = no.
{&SQQOMTLB-P-TAG3}
